package com.yc.bean1;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author zwei
 * @create 2024-07-28 15:40
 */
@Configuration      //这是一个配置类  作用相当于  bean.xml
public class AppConfig {
    @Autowired
    private ApplicationContext context;
    @Bean   //这就是ioc  相当于上面这一句xml
    public Address addr(){
        Address a=new Address();
        a.setCity("衡阳");
        a.setProvince("湖南");
        a.setDistrict("珠晖区");
        return a;
    }
    @Bean
    public Student s1(){
        Student s=new Student();
        s.setName("张三");
        s.setId(1);
        s.setAddress((Address) context.getBean("addr"));
        return s;
    }
}
